package utils;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import api.IFacade;
import api.IGameEngine;



/**
 * @author $Author:$
 * @version $Id: $
 */
public class JNDIServices {
	private static InitialContext ctx;
	static{
		try {
			Properties properties = new Properties();
			
			
			properties.setProperty(Context.PROVIDER_URL	, "jnp://localhost:1099");
			properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
			properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");



			//InputStream is = JNDIServices.class.getResourceAsStream("jndi.properties");
			//properties.load(is);
			
			
			
			ctx = new InitialContext();
			for(Entry<Object,Object> entry: properties.entrySet())
				ctx.addToEnvironment((String)entry.getKey(),(String)entry.getValue());
			
			
			
			
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public static IFacade getFacade() throws NamingException {
		
		return (IFacade) ctx.lookup("EAI2/IFacade/remote");
		
	}
	
public static IGameEngine getGameEngine() throws NamingException {
		
		return (IGameEngine) ctx.lookup("EAI2/IGameEngine/remote");
		
	}
	
	
}
